package cn.edu.nwsuaf.examcenter.service.serviceImpl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import cn.edu.nwsuaf.examcenter.model.PageModel;
import cn.edu.nwsuaf.examcenter.model.StudentScoreModel;
import cn.edu.nwsuaf.examcenter.pojo.StudentExamScore;
import cn.edu.nwsuaf.examcenter.pojo.StudentExamScoreId;
import cn.edu.nwsuaf.examcenter.service.StudentExamScoreService;

@Service(value="studentExamScoreService")
public class StudentExamScoreServiceImpl extends BaseServiceImpl<StudentExamScore> implements StudentExamScoreService {

	@Override
	public void getStudentExamScore(String studentNo, List<String> examList, List<StudentScoreModel> modelList) {
		// TODO Auto-generated method stub
		for(int i = 0; i<examList.size(); i++){
			if(examList.get(i)==null){
				modelList.get(i).setExamScore(0);
			}else{
				StudentExamScoreId id = new StudentExamScoreId();
				id.setStudentNo(studentNo);
				id.setExamPaperNo(examList.get(i));
				
				StudentExamScore examScore = super.getById(StudentExamScore.class, id);
				if(examScore==null){
					modelList.get(i).setExamScore(0);
				}else{
					modelList.get(i).setExamScore(examScore.getScore());
				}
			}
		}
	}

	@Override
	public void loadStudentExamScore(String studentNo, ModelMap modelMap) {
		// TODO Auto-generated method stub
		String hql = "FROM StudentExamScore where student.studentNo=?";
		String[] param={studentNo};
		
		PageModel<StudentExamScore> pageModel = new PageModel<>();
		
		List<StudentExamScore> list = super.findAll(hql, param);
		
		pageModel.setTotalrows(list.size());
		pageModel.setList(list);
		
		modelMap.addAttribute("pageModel",pageModel);
	}

}
